<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    /* 通用样式 */
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 20px;
      background-color: #f5f5f5;
    }
    .container {
      max-width: 400px;
      margin: 50px auto;
      padding: 20px;
      background: white;
      border-radius: 8px;
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    h1 {
      text-align: center;
      color: #333;
      margin-bottom: 20px;
    }
    input[type="text"], input[type="password"] {
      width: 100%;
      padding: 10px;
      margin: 10px 0;
      border: 1px solid #ddd;
      border-radius: 4px;
      box-sizing: border-box;
    }
    input[type="submit"] {
      width: 100%;
      padding: 10px;
      background-color: #007bff;
      color: white;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }
    input[type="submit"]:hover {
      background-color: #0056b3;
    }
    a {
      display: block;
      text-align: center;
      margin-top: 20px;
      color: #007bff;
      text-decoration: none;
    }
    a:hover {
      text-decoration: underline;
    }
    .status {
      margin-top: 20px;
      padding: 10px;
      border-radius: 4px;
      text-align: center;
    }
    .success {
      background-color: #d4edda;
      color: #155724;
    }
    .error {
      background-color: #f8d7da;
      color: #721c24;
    }
  </style>
</head>
<body>
  <!-- 登录页面 -->
  <div id="loginPage" class="container">
    <h1>Login</h1>
    <form action="/login" method="POST">
      <input type="password" name="password" placeholder="Enter password">
      <input type="submit" value="Login">
    </form>
  </div>

  <!-- 主页面 -->
  <div id="mainPage" class="container">
    <h1>Welcome!</h1>
    <p>You have successfully logged in.</p>
    <a href="/change_password">Change Password</a>
    <a href="/wifi_config">WiFi Configuration</a>
  </div>

  <!-- WiFi配置页面 -->
  <div id="wifiConfigPage" class="container">
    <h1>WiFi Configuration</h1>
    <form action="/wifi_config" method="POST">
      <label>SSID:</label>
      <input type="text" name="ssid" placeholder="Enter WiFi SSID" required>
      <label>Password:</label>
      <input type="password" name="password" placeholder="Enter WiFi password">
      <input type="submit" value="Save & Connect">
    </form>
    <div id="status"></div>
  </div>

  <!-- 修改密码页面 -->
  <div id="changePasswordPage" class="container">
    <h1>Change Password</h1>
    <form action="/change_password" method="POST">
      <label>Current Password:</label>
      <input type="password" name="current_password" placeholder="Enter current password">
      <label>New Password:</label>
      <input type="password" name="new_password" placeholder="Enter new password">
      <label>Confirm New Password:</label>
      <input type="password" name="confirm_password" placeholder="Confirm new password">
      <input type="submit" value="Change Password">
    </form>
  </div>

  <!-- 成功页面 -->
  <div id="successPage" class="container">
    <h1>Password Changed Successfully!</h1>
    <a href="/">Back to Login</a>
  </div>

  <!-- 错误页面 -->
  <div id="errorPage" class="container">
    <h1>Error Changing Password</h1>
    <p>%s</p>
    <a href="/change_password">Try Again</a>
  </div>

  <script>
    // WiFi配置页面的状态显示
    function showStatus(message, isSuccess) {
      const statusDiv = document.getElementById('status');
      statusDiv.className = 'status ' + (isSuccess ? 'success' : 'error');
      statusDiv.textContent = message;
    }
    
    const urlParams = new URLSearchParams(window.location.search);
    const status = urlParams.get('status');
    const message = urlParams.get('message');
    
    if (status && message) {
      showStatus(message, status === 'success');
    }
  </script>
</body>
</html>
